package com.ruoyi.api.abuwx.service.impl;

import com.ruoyi.abuwx.domain.UmsUser;
import com.ruoyi.abuwx.service.IUmsUserService;
import com.ruoyi.api.abuwx.domain.dto.UserDto;
import com.ruoyi.api.abuwx.service.UserService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.satoken.StpClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zouhuu
 * @description 客户端 用户管理模块 服务层
 * @date 2022/07/04 16:21:13
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private IUmsUserService iUmsUserService;

    /**
     * 用户信息
     * @return
     */
    @Override
    public AjaxResult userInfo() {
        return AjaxResult.success(iUmsUserService.selectUmsUserById(StpClientUtil.getLoginIdAsLong()));
    }

    /**
     * 新增用户
     * @return
     */
    @Override
    public AjaxResult Save(UserDto userDto) {

        UmsUser umsUser = new UmsUser();
        umsUser.setUid(StpClientUtil.getLoginIdAsLong());
        umsUser.setUsername(userDto.getUsername());
        umsUser.setPhone(userDto.getPhone());
        umsUser.setContactPhone(userDto.getContactPhone());
        umsUser.setRegion(userDto.getRegion());
        umsUser.setCompanyName(userDto.getCompanyName());
        umsUser.setEmail(userDto.getEmail());
        if (StringUtils.isNull(userDto.getId()) ) { //新增用户
            iUmsUserService.insertUmsUser(umsUser);
        } else {
            umsUser.setId(userDto.getId());//修改用户
            iUmsUserService.updateUmsUser(umsUser);
        }
    return AjaxResult.success("ok");
    }
}
